'use strict';

exports.main = async(event, context) => {
    /* data格式
    {
        addressee: 'xxxx@xx.xx', // 收件人地址
        subject: 'xxxx', // 邮件主题
        text: 'xxxxxx' // 正文

    }
     */
    const mailgun = require("mailgun-js");
    const DOMAIN = 'sandbox249ed5376daa44a2baabd83d3cb2bf9b.mailgun.org';
    const api_key = '7aa7bf7e23105b1726efa09a409768fc-468bde97-aeddf80e'
    const mg = mailgun({ apiKey: api_key, domain: DOMAIN });
    const data = {
        from: '云开发 <me@sandbox249ed5376daa44a2baabd83d3cb2bf9b.mailgun.org>',
        to: event.addressee, // 如果有多个收件人以逗号分隔："xxx1@qq.com, xxx2@qq.com"
        subject: event.subject, // 主题
        text: event.text + '\n' + '编号：' + Math.ceil(Math.random()*100), //详细内容
    };
    mg.messages().send(data, function(error, body) {
        console.log(body)
    });

};